﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="mail_smtp.aspx.cs" Inherits="backmanage_mailsystem_mail_smtp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>发信设置</title>
    <script type="text/javascript" src="../js/jquery-1.6.1.js"></script>
    <script type="text/javascript">
      $(function(){
        var stat="add";
        var smtpid;
        function infoList()
        {
         $.post("../API/A_Email.aspx",{"edit":"smtplist"},function(msg){$("table tbody").html(msg);},"html")
        }
        function infoAdd()
        {
              var address=$("#address").val();
              var port=$("#port").val();
              var username=$("#username").val();
              var password=$("#password").val();
              if(address.length==0||port.length==0||username.length==0||password.length==0)
              {
                 alert("请填写完整信息!");
                 return false;
              }
            if(stat=="add")
            {
                  $.post("../API/A_Email.aspx",{"edit":"smtpadd","address":address,"port":port,"username":username,"password":password},function(msg){
                       infoList();
                  },"html")
            }
            else{
                $.post("../API/A_Email.aspx",{"edit":"smtpupdate","address":address,"port":port,"username":username,"password":password,"id":smtpid},function(msg){
                       infoList();
                  },"html")
            }
        }
        function editState(e)
        {
          var edit=$(e).attr("title");
          var id=$(e).parent().parent().attr("id");
          if(edit=="update")
          {
              stat="update";
              if(id.length>0)
               smtpid=id;
              $.post("../API/A_Email.aspx",{"edit":"smtpinfo","id":id},function(data){
                 $("#address").val(data.address);
                 $("#port").val(data.port);
                 $("#username").val(data.username);
                 $("#password").val(data.password);
              },"json");
          }
          else if(edit=="delete")
          {
            $.post("../API/A_Email.aspx",{"edit":"smtpdelete","id":id},function(msg){
                       infoList();
                 $("#address").val("");
                 $("#port").val("");
                 $("#username").val("");
                 $("#password").val("");
                  },"html")
          }
        }
        $(document).ready(function(){
           $("#sumbit").live("click",function(){infoAdd();});
           $("tbody a").live("click",function(){editState(this);});
           infoList();
        });
      });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      SMTP地址：<input id="address" type="text" />SMTP端口<input id="port" type="text" /><br />
      SMTP用户名：<input id="username" type="text" />SMTP密码：<input id="password" type="password" />
      <input id="sumbit" type="button" value="提交" />
    </div>
    <div>
      <table>
        <thead>
          <tr>
            <td>SMTP地址</td>
            <td>SMTP端口</td>
            <td>SMTP用户名</td>
            <td>添加人</td>
            <td>操作</td>
          </tr>
        </thead>
        <tbody></tbody>
        <tfoot></tfoot>
      </table>
    </div>
    </form>
</body>
</html>
